<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
	<meta name="viewport" content="user-scalable=no,viewport-fit=cover" />
	<link href="./css/baseCss.css" rel="stylesheet" type="text/css"/>
	<link href="./css/detailComment.css" rel="stylesheet" type="text/css"/>
	<link href="./base/layer.css" rel="stylesheet" type="text/css"/>
	<!-- <link href="./base/articlecon.css" rel="stylesheet" type="text/css"/> -->
	<link href="./base/base2.css" rel="stylesheet" type="text/css"/>
	<link rel="stylesheet" type="text/css" href="./css/swiper-3.4.0.min.css">
	<script type="text/javascript" src="./base/rem.js"></script>
	<script type="text/javascript" src="./base/iscroll.js"></script>
	
	<!-- <link rel="stylesheet" type="text/css" href="./css/detail.css"> -->
	<style type="text/css">
		
	</style>
	<title>餐厅详情页-评论</title>
</head>
<body>
	<div class="container">
		<div class="detail-top">
			<div class="detail-top-bg">
				<img class="bgImg" src="./img/bg_01.png">
				<!-- <div class="detail-top-love"><img src="./img/heart_01.png"><img src="./img/share_01.png"></div> -->
			</div>
			<div class="detail-top-name">欢乐汇餐厅</div>
			<div  class="detail-top-prefer"><span class="prefer">满减</span><span>满20减2;</span><span>满30减4;</span><span>满50减7</span></div>
			<div class="detail-top-size">
				<span>味道赞</span><span>包装好</span><span>价格实惠</span><span>服务好</span>
			</div>
			<div><img class="logoImg" src="./img/root_03.png"></div>
		</div>
		<div class="detail-bar">
			<div class="detail-sw">
				<div onclick="detailDis('detail');">点菜</div><div class="detail-current">评价</div><div onclick="detailDis('detailMerchant');">商家</div>
			</div>
			<div class="detail-dish">
				<div class="detail-score">
					<div class="detail-score-red" id="evaluationLevel">4.7</div>
					<div class="detail-score-merchant">
						<div>商家评分</div>
						<div id="starInc"><img src="./img/start.png"></div>
					</div>
					<div class="detail-score-inc">
						<div class="detail-score-every">
							<div class="detail-score-title">味道</div>
							<div id="tasteLevel">4.7</div>
						</div>
						<div class="detail-score-every">
							<div class="detail-score-title">服务</div>
							<div id="serviceLevel">4.7</div>
						</div>
						<div class="detail-score-every">
							<div class="detail-score-title">包装</div>
							<div id="packLevel">4.7</div>
						</div>
						<div class="detail-score-every">
							<div class="detail-score-title">配送</div>
							<div id="deliveryLevel">4.7</div>
						</div>
					</div>
				</div>
				
				<div class="detail-type">
					<div data-searchType="1" class="detail-type-org detail-type-target" onclick="findRestaurantEvaluationList(1,this);">全部<span id="allCnt" class="detail-type-num">000</span></div>
					<!-- <div class="detail-type-org" onclick="findRestaurantEvaluationList(2,this);">最新<span class="detail-type-num">000</span></div> -->
					<div data-searchType="3" class="detail-type-org" onclick="findRestaurantEvaluationList(3,this);">好评<span id="goodCnt" class="detail-type-num">000</span></div>
					<div data-searchType="4" class="detail-type-org detail-type-bad" onclick="findRestaurantEvaluationList(4,this);">差评<span id="loseCnt" class="detail-type-num">000</span></div>
					<div data-searchType="5" class="detail-type-org" onclick="findRestaurantEvaluationList(5,this);">有图<span id="imgCnt" class="detail-type-num">000</span></div>
					<div data-searchType="6" class="detail-type-org" onclick="findRestaurantEvaluationList(6,this);">味道好<span id="tasteCnt" class="detail-type-num">000</span></div>
				</div>

				<ul>
					<!-- <li class="desc-li">
						<div class="desc-bar">
							<div class="desc-bar-img"><img class="imgBai" src="./img/root_04.png"></div>
							<div class="desc-bar-state">
								<div>会飞的鱼</div>
								<div><img src="./img/zan_01.png">赞了该商品</div>
							</div>
							<div class="desc-bar-date">2012.12.21</div>
						</div>
						<div class="desc-li-text">很好吃，下次还会再来</div>
					</li>
					<li class="desc-li">
						<div class="desc-bar">
							<div class="desc-bar-img"><img class="imgBai" src="./img/root_04.png"></div>
							<div class="desc-bar-state">
								<div>会飞的鱼</div>
								<div><img src="./img/zan_01.png">赞了该商品</div>
							</div>
							<div class="desc-bar-date">2012.12.21</div>
						</div>
						<div class="desc-li-text">很好吃，下次还会再来</div>
					</li> -->
				</ul>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript" src="./js/jquery.min.js"></script>
<script type="text/javascript" src="./js/httpUnit.js"></script>
<script type="text/javascript" src="./js/constants.js"></script>
<script type="text/javascript">
	getRestaurantInfo();
	findRestaurantEvaluationList(1);
	//餐厅信息
	function getRestaurantInfo(){
		//var detailInfo = JSON.parse(sessionStorage.getItem("detailInfo"));
		var Request = new Object();
		Request = GetRequest();
		//var id = detailInfo.restaurantId;
        var id = Request['id'];
		var obj = JSON.stringify({
			"id": id,
		});
	
		httpHelperpost(_API_GETRESTAURANT_INFO, obj, function(isSuccess, data) {
	        if (isSuccess == true) {
	            var response = data.responseText;
	            var value = JSON.parse(response);
	    			
	   			// console.log(response);
	   			
	            if(value.code == 0){
	             	console.log("查询成功");
	             	var dispatchPrice = value.data.dispatchPrice;
	   				$(".logoImg").attr("src",value.data.icon);
	   				$(".detail-top-name").text(value.data.name);
	   				$("#dispatchPrice").text(dispatchPrice==null?dispatchPrice=0:dispatchPrice);
	   				// $("#totalPrice").text(dispatchPrice);
					$("#evaluationLevel").html(value.data.evaluationLevel);
                    $("#tasteLevel").html(value.data.tasteLevel);
                    $("#serviceLevel").html(value.data.serviceLevel);
                    $("#packLevel").html(value.data.packLevel);
                    $("#deliveryLevel").html(value.data.deliveryLevel);
	   				var activity = new Array();
	   				activity = value.data.fullReduceActivity.split(";");
	   				var activityHtml = "";
	   				for(var i=0;i<activity.length-1;i++){
	   					activityHtml += "<span>"+activity[i]+"</span>";
	   				}
	   				$(".prefer-inc").html(activityHtml);

	   				var starHtml = "";
	   				for(var i=0,len=Math.round(parseFloat(value.data.evaluationLevel));i<len;i++){
	   					starHtml+="<img src='./img/start.png'>";
	   				}
	   				$("#starInc").html(starHtml);
	            }else if(value.code==401){
	            	alert(value.message);
	            	window.location.href='./index.html';
	            }else{
	            	alert(value.message);
	             	console.log("查询失败");
	            }
	        }else {}
	    });
	}

	//获取商家评论列表
	function findRestaurantEvaluationList(searchType,that){
		var page = 0;
		var isRefresh = false;
		if(that==undefined||that==null){
			page = Math.ceil(parseInt($(".desc-li").length)/10);
			isRefresh = true;
		}else{
			$(that).addClass("detail-type-target").siblings().removeClass("detail-type-target");
		}

		var Request = new Object();
		Request = GetRequest();
		var id = Request['id'];
		
        var size = 10;
        
        var sort = new Array();
        sort.push("id");
		var obj = JSON.stringify({
			"restaurantId": id,
			"searchType":searchType
		});
	
		httpHelperpost("/api/restaurantEvaluations/findRestaurantEvaluationList?page="+page+"&size="+size+"&sort="+sort, obj, function(isSuccess, data) {
	        if (isSuccess == true) {
	            var response = data.responseText;
	            var value = JSON.parse(response);
	    			
	   			// console.log(response);
	   			
	            if(value.code == 0){
	            	$("#tasteCnt").text(value.data.tasteCnt);
	             	$("#allCnt").text(value.data.allCnt);
	             	$("#goodCnt").text(value.data.goodCnt);
	             	$("#loseCnt").text(value.data.loseCnt);
	             	$("#imgCnt").text(value.data.imgCnt);

	             	var html ="";
	   				for(var i=0;i<value.data.reList.length;i++){
	   					html += "<li class='desc-li'>"
	   						+"<div class='desc-bar'>"
							+"<div class='desc-bar-img'><img class='imgBai' src="+value.data.reList[i].userLogo+"></div>"
							+"<div class='desc-bar-state'>"	
							+"<div>"+value.data.reList[i].userName+"</div>"	
							+"<div class='desc-start'>";
								var len = 0;
								if(searchType==1||searchType==3||searchType==4||searchType==5){
									len=Math.round(levelisNull(value.data.reList[i].foodLevel));
								}else if(searchType==6){
									len=Math.round(levelisNull(value.data.reList[i].tasteLevel));
								}
								for(var j=0;j<len;j++){
                            	    html+="<img src='./img/start.png'>";
                            	}
						html+="</div>"		
							+"</div>"		
							+"<div class='desc-bar-date'>"+value.data.reList[i].evaluationTime.substring(0,10)+"</div>"	
							+"</div>"
							+"<div class='desc-li-text'>"+value.data.reList[i].evaluationContent+"</div>"
							+"</li>";	
	   				}
					
					if(isRefresh == true){
						$(".detail-dish ul").append(html);
					}else if(isRefresh==false){
						$(".detail-dish ul").html(html);
					}
	   				
	             	console.log("查询成功");
	             	if(value.data.reList==""){

	             	}else{
	             		dropreFresh();
	             	}
	            }else if(value.code==401){
	            	alert(value.message);
	            	window.location.href='./index.html';
	            }else{
	            	alert(value.message);
	             	console.log("查询失败");
	            }
	        }else {}
	    });

	    function levelisNull(value){
    	    if(value==null||value==undefined){
    	        value = 0;
    	    }
    	    return value;
    	}
	}

	//下拉刷新
	function dropreFresh(){
		$(window).bind("scroll",function() {
			var scrollTop = $(document).scrollTop();//滚动条距离页面顶部距离
			var offsetHeight = $(document).height();//当前页面高度(包括滚动页面)
			var clientHeight = $(this).height();//当前页面高度(不包括滚动页面)
			var bottomHeight = scrollTop-(offsetHeight-clientHeight);
			if(bottomHeight<1&&bottomHeight>-2){
				// console.log(bottomHeight);
				var searchType = $(".detail-type .detail-type-target").attr("data-searchType");
				findRestaurantEvaluationList(searchType);
				$(window).unbind("scroll");
			}
		});
	}

	//跳转逻辑
	function detailDis(url){
		var Request = new Object();
        Request = GetRequest();
        var id = Request['id'];
		window.location.href = './'+url+".html?id="+id;
	}

	//获取url中"?"符后的字串
	function GetRequest() {
	    var url = location.search; //获取url中"?"符后的字串   
	    
	    var theRequest = new Object();
	    if (url.indexOf("?") != -1) {
	      var str = url.substr(1);
	      
	      strs = str.split("&");
	      
	      for (var i = 0; i < strs.length; i++) {
	        
	        theRequest[strs[i].split("=")[0]] = strs[i]
	            .split("=")[1];
	      }
	    }
	    return theRequest;
	}
	
</script>
</html>